// pages/bookdetail/bookdetail.js
import { getChapter, changeMyBook } from "../../utils/api.js";
Page({

    /**
     * 页面的初始数据
     */
    data: {
        path: "https://img.yuncoding.cn/souti/book",
        catalog: [],
        rowIcon: '/image/down@2x.png',
        isAdd: 0,
        bookId: 0,
        bookName: "",
        bookCover: "",
        bookAuthor: "",
        bookUniv: ""
    },
    /**
     * 生命周期函数--监听页面加载
     */
    closeOther: function (e) {
        // console.log(e);
        var current = e.detail.current;
        var catArr = this.selectAllComponents('.catalog');

        catArr.forEach((item) => {
            item.closeChildren(current);
        })
    },
    onLoad: function (options) {
        // console.log(options.id)
        wx.setNavigationBarTitle({
            title: options.bookName,
        })
        this.setData({
            isAdd: options.isAdd,
            bookId: options.bookId,
            bookName: options.bookName,
            bookCover: options.bookCover,
            bookAuthor: options.bookAuthor,
            bookUniv: options.bookUniv
        })
        getChapter(options.bookId, (data) => {
            this.setData({
                catalog: data
            })
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {
        wx.showNavigationBarLoading();
        getChapter(this.data.bookId, (data) => {
            data.forEach((item) => {
                item[0].icon = '/image/down@2x.png';
                item[0].isShow = true;
            })
            this.setData({
                catalog: data
            });
            wx.hideNavigationBarLoading();
            wx.stopPullDownRefresh();
        })
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})